const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    zone: null,
    module: null,
    light: 1,
    R: 255,
    G: 0,
    B: 0,


    //----------------------------------------
    zoneList: [{
      code: 0,
      name: '主分区'

    }, {
      code: 1,
      name: '分区一'

    }, {
      code: 2,
      name: '分区二'

    }],
    lightList: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
    moduleList: [{
        module: '关闭',
        code: 0
      }, {
        module: '单色模式',
        code: 1
      },
      {
        module: '呼吸模式',
        code: 2
      },
      {
        module: '渐变模式',
        code: 3
      },
      {
        module: '爆闪模式',
        code: 4,
      },
      {
        module: '律动模式',
        code: 5,
      }
    ]

  },
  onShow: function () {
    if (!app.globalData.deviceId) {
      // wx.switchTab({
      //   url: '/pages/index/index'
      // });
    }
  },
  onZone(e) {
    let val = e.detail.value;
    this.setData({
      zone: this.data.zoneList[val]
    })
  },
  onModule(e) {
    let val = e.detail.value;
    this.setData({
      module: this.data.moduleList[val]
    })
  },
  onLight(e) {
    let val = e.detail.value;
    this.setData({
      light: this.data.lightList[val]
    })
  },
  //重置参数
  reset() {
    this.setData({
      zone: null,
      module: null,
      light: 1,
      R: 255,
      G: 0,
      B: 0,
    })
    app.Toast('重置参数成功!')
  },
  //确认参数
  confirm() {
    let data = this.data;
    if (!data.zone) {
      app.Toast('未选中分区！')
      return
    }
    if (!data.module) {
      app.Toast('未选中模式！')
      return
    }

    app.globalData.code_3 = data.zone.code;
    app.globalData.code_4 = data.module.code2;
    app.globalData.code_5 = data.light|| 5;
    app.globalData.code_6 = data.R || 0;
    app.globalData.code_7 = data.G || 0;
    app.globalData.code_8 = data.B || 0;


    app.writeBLE()


  }
})